package com.shirley.slxxljob.job;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class SlXxlJob {

    @XxlJob("failedJob")
    public void failedJob() throws InterruptedException {
        XxlJobHelper.log("A simple bean job");
        for (int i = 0; i < 5; i++) {
            XxlJobHelper.log("beat at:" + i);
            TimeUnit.SECONDS.sleep(1);
        }
        XxlJobHelper.handleFail("Test failed.");
    }


    @XxlJob("successJob")
    public void successJob() throws InterruptedException {
        XxlJobHelper.log("A simple success bean job");
        XxlJobHelper.log("JobId={}, JobParam={}, ShardiIndex={}, ShardTotal={}",
                XxlJobHelper.getJobId(),
                XxlJobHelper.getJobParam(),
                XxlJobHelper.getShardIndex(),
                XxlJobHelper.getShardTotal());
        for (int i = 0; i < 5; i++) {
            XxlJobHelper.log("beat at:" + i);
            TimeUnit.SECONDS.sleep(1);
        }
        XxlJobHelper.handleSuccess("Job done success.");
    }
}
